package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.passport.pojo.dto.AdminAddNewDTO;
import cn.tedu.csmall.passport.pojo.dto.AdminLoginDTO;
import cn.tedu.csmall.passport.pojo.vo.AdminListItemVO;
import cn.tedu.csmall.passport.service.IAdminService;
import cn.tedu.csmall.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "1.管理员管理模块")
@Slf4j
@RequestMapping("/admins")
public class AdminController {
    @Autowired
    IAdminService adminService;
    @PostMapping("/add-new")
    @ApiOperation("添加管理员")
    @ApiOperationSupport(order = 401)
    public JsonResult addNew(@RequestBody AdminAddNewDTO adminAddNewDTO){
        log.debug("接收到的请求参数：{}", adminAddNewDTO);
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("")
    @ApiOperation("查询管理员列表")
    @ApiOperationSupport(order = 401)
    public JsonResult list(){
        log.debug("管理员列表请求");
        List<AdminListItemVO> admins = adminService.list();
        return JsonResult.ok(admins);
    }
    @PostMapping("/login")
    @ApiOperation("管理员登陆")
    @ApiOperationSupport(order = 400)
    public JsonResult login(@RequestBody AdminLoginDTO adminLoginDTO){
        log.debug("处理登陆请求方法参数:{}",adminLoginDTO);
        String jwt = adminService.login(adminLoginDTO);
        return JsonResult.ok(jwt);
    }
}
